<template>
  <div>
  <a-row style="margin-bottom: 10px;" :gutter="12">
    <a-col :span="6">
      <a-card :bordered="false"  @click="filterInst(2)">
        <div style="display: flex;align-items:center;margin-top: 8px;">
          <div style="border-radius:8px;background-color: #0a91f9; padding:12px;margin-right: 24px">
            <img src="~@assets/eneMon/peidianjiance.svg" width="32" height="32"/>
          </div>
          <div>
            <div>全部</div>
            <div style="font-size: 18px; font-weight: 600; margin-top: 5px;">{{total }}</div>
          </div>
        </div>
      </a-card>
    </a-col>
    <a-col :span="6">
      <a-card :bordered="false" style="height: 110px;cursor: pointer" @click="filterInst(1)">
        <div style="display: flex; align-items:center;margin-top: 8px;" >
          <div style="border-radius:8px;background-color: #00e166; padding:12px;margin-right: 24px">
            <img src="~@assets/eneMon/peidianjiance.svg" width="32" height="32"/>
          </div>
          <div>
            <div>已审批</div>
            <div style="font-size: 18px; font-weight: 600; margin-top: 5px;">{{over}}</div>
          </div>
        </div>
      </a-card>
    </a-col>
    <a-col :span="6">
      <a-card :bordered="false" style="height: 110px;cursor: pointer" @click="filterInst(0)">
        <div style="display: flex; align-items:center;margin-top: 8px;" >
          <div style="border-radius:8px;background-color: #d3321c; padding:12px;margin-right: 24px">
            <img src="~@assets/eneMon/peidianjiance.svg" width="32" height="32"/>
          </div>
          <div>
            <div>已驳回</div>
            <div style="font-size: 18px; font-weight: 600; margin-top: 5px;">{{reject}}</div>
          </div>
        </div>
      </a-card>
    </a-col>
    <a-col :span="6">
      <a-card :bordered="false" style="height: 110px;cursor: pointer" @click="filterInst(-1)">
        <div style="display: flex; align-items:center;margin-top: 8px;">
          <div style="border-radius:8px;background-color: #cbcbcb; padding:12px;margin-right: 24px">
            <img src="~@assets/eneMon/peidianjiance.svg" width="32" height="32"/>
          </div>
          <div>
            <div>待审批</div>
            <div style="font-size: 18px; font-weight: 600; margin-top: 5px;">{{wait}}</div>
          </div>
        </div>
      </a-card>
    </a-col>
  </a-row>
  <a-row :gutter="12">
    <a-col >
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="提报人">
                <j-select-multi-user :multiple='false' v-model="queryParam.createBy" />
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="提报日期">
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="仪表编号">
                <a-input placeholder="请输入仪表编号" v-model="queryParam.ref"></a-input>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="审批时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.approveTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.approveTime_end"></j-date>
              </a-form-item>
            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="能源数据类型">
                <j-dict-select-tag placeholder="请选择能源数据类型" v-model="queryParam.eneTypeId" dictCode="ene_energy_type,type,id"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
       <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

<!--      <a-button @click="handleImport" type="primary" icon="import">导入</a-button>-->
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('非电导入数据表审批表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
        class="j-table-force-nowrap1"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <a @click="handleEdit(record,'审批')" v-if="record.approveStatus=='-1'&&record.approveUser==username">审批</a>

          <a @click="handleEdit(record,'修改')" v-if="record.approveStatus=='0'&&record.createBy==username">修改</a>

          <a-divider type="vertical"v-if="(record.approveStatus=='-1'&&record.approveUser==username)||(record.approveStatus=='0'&&record.createBy==username)" />

           <a @click="handleDetail(record)">详情</a>
<!--          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <un-power-export-temp-modal ref="modalForm" @ok="modalFormOk"></un-power-export-temp-modal>
    <ins-copy-modal ref="inscopy" @ok="modalFormOk"></ins-copy-modal>
    <ins-copy-import ref="insimport" @ok="modalFormOk"></ins-copy-import>
  </a-card>
    </a-col>
  </a-row>
</div>
</template>

<script>

  import '@assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import UnPowerExportTempModal from './modules/UnPowerExportTempModal.vue'
  import InsCopyModal from './modules/InsCopyModal.vue'
  import InsCopyImport from './modules/InsCopyImport.vue'
  import { getAction } from '@api/manage'
  export default {
    name: 'InsCopy',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      UnPowerExportTempModal,
      InsCopyModal,
      InsCopyImport
    },
    data () {
      return {
        username:this.$store.getters.userInfo.username,
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        description: '非电导入数据表审批表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy_dictText'
          },
          {
            title:'仪表编号',
            align:"center",
            dataIndex: 'ref'
          },
          {
            title:'仪表名称',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'位置',
            align:"center",
            dataIndex: 'position'
          },
          {
            title:'用能分区',
            align:"center",
            dataIndex: 'zone_dictText'
          },
          {
            title:'抄录日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'结束表数',
            align:"center",
            dataIndex: 'endMeterValue'
          },
          {
            title:'审批状态',
            align:"center",
            dataIndex: 'approveStatus_dictText'
          },
          {
            title:'审批人',
            align:"center",
            dataIndex: 'approveUser_dictText'
          },
          {
            title:'能源数据类型',
            align:"center",
            dataIndex: 'eneTypeId_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/eneMon/unPowerExportTemp/list",
          count: "/eneMon/unPowerExportTemp/count",
          delete: "/eneMon/unPowerExportTemp/delete",
          deleteBatch: "/eneMon/unPowerExportTemp/deleteBatch",
          exportXlsUrl: "/eneMon/unPowerExportTemp/exportXls",
          importExcelUrl: "eneMon/unPowerExportTemp/importExcel",

        },
        total:0,
        over:0,
        reject:0,
        wait:0,
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    this.getCount()
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      getCount(){
        getAction(this.url.count).then((res)=>{
         this.total=0
         this.over=0
         this.reject=0
         this.wait=0
         res.result.forEach(key=>{
             switch (key.approve_status) {
               case "1":
                 this.over=key.count
                 break;
               case "0":
                 this.reject=key.count
                 break;

               case "-1":
                 this.wait=key.count
                 break;
             }
           })
          this.total=this.over+this.reject+this.wait

        })
      },
      filterInst(record){
        switch (record) {
          case 2:
            delete this.queryParam.approveStatus
            break;
          default:
            this.queryParam.approveStatus=record
            break;
        }
        this.searchQuery()
      },
      handleAdd(){
        this.$refs.inscopy.add();
        this.$refs.inscopy.title = "新增";
        this.$refs.inscopy.disableSubmit = false;
      },
      handleImport(){
        this.$refs.insimport.add();
        this.$refs.insimport.title = "导入";
        this.$refs.insimport.disableSubmit = false;

      },
      handleEdit(record,text) {
        this.$refs.modalForm.edit(record,text);
        this.$refs.modalForm.title = text;
        this.$refs.modalForm.disableSubmit = false;
      },

      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'ref',text:'仪表编号',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'仪表名称',dictCode:''})
        fieldList.push({type:'string',value:'position',text:'位置',dictCode:''})
        fieldList.push({type:'sel_search',value:'zone',text:'用能分区',dictTable:'xsd_unit_part', dictText:'unit_name', dictCode:'id'})
        fieldList.push({type:'BigDecimal',value:'endMeterValue',text:'结束表数',dictCode:''})
        fieldList.push({type:'string',value:'approveStatus',text:'审批状态',dictCode:'approve_status'})
        fieldList.push({type:'string',value:'approveRemarks',text:'审批备注',dictCode:''})
        fieldList.push({type:'string',value:'approveUser',text:'审批人',dictCode:''})
        fieldList.push({type:'datetime',value:'approveTime',text:'审批时间'})
        fieldList.push({type:'string',value:'eneTypeId',text:'能源数据类型',dictCode:'ene_energy_type,type,id'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>